1 Public Class FrmCatITEMADD
2 Dim stockID
3 Private Sub cmdcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdcancel.Click
4 Me.Close()
5 End Sub
6
7 Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
8 Dim msg As String, msgERR As String
9 Dim tmp_barcode As Integer
10 Dim duplicate_barcode As Boolean
11 Dim duplicate_item_number As Boolean
12
13 msg = "Please Complete The Following " & Chr(10) & " --------------------------- "
14 msgERR = msg
15 If txtname.Text = "" Then
16 msg = msg & Chr(10) & " Item Name : < Should not be blank >"
17 End If
18 If txtdesc.Text = "" Then
19 msg = msg & Chr(10) & " Item Description : < Should not be blank > "
20 End If
21 If cmbUnit.Text = "" Then
22 msg = msg & Chr(10) & " Item Measure : < Should not be blank > "
23 End If
24 If Not IsNumeric(txtbarcode.Text) Then
25 msg = msg & Chr(10) & " Barcode: < Should be numeric >"
26 End If
27
28 If Not IsNumeric(txtreorder.Text) Then
29 msg = msg & Chr(10) & " Reorder Point: < Should be numeric >"
30 End If
31
32 If Not IsNumeric(txtprice.Text) Then
33 msg = msg & Chr(10) & " Price : < Should be numeric >"
34 End If
35
36 If Len(txtbarcode.Text) < 4 Then
37 msg = msg & Chr(10) & " Barcode : < Barcode minimum length should be 4 >"
38 End If
39 If msg <> msgERR Then
40 MsgBox(msg, MsgBoxStyle.Information, "Sales and Inventory")
41 Exit Sub
42 End If
43 If Len(txtbarcode.Text) > 13 Then
44 MsgBox("Barcode length should not be lower than 13 !! ", MsgBoxStyle.Exclamation, "Sales and Inventory")
45 Exit Sub
46 End If
47 If Split(Me.Text, " - ")(1) = "Edit" Then
48 sqlSTR = "SELECT * FROM TBL_Category_Item_File WHERE Item_ID =" & txtID.Text
49 ExecuteSQLQuery(sqlSTR)
50 tmp_barcode = sqlDT.Rows(0)("Item_Barcode")
51 If R_Change(sqlDT.Rows(0)("Item_Description")) = txtdesc.Text Then
52 duplicate_item_number = False
53 Else
54 sqlSTR = "SELECT * FROM TBL_Category_Item_File WHERE Item_Description ='" & txtdesc.Text & "'"
55 ExecuteSQLQuery(sqlSTR)
56 If sqlDT.Rows.Count > 0 Then
57 MsgBox("Item Number Already Exist !!", MsgBoxStyle.Exclamation, "Sales and Inventory")
58 duplicate_item_number = True
59 Exit Sub
60 Else
61 duplicate_item_number = False
62 End If
63 End If
64
65 If tmp_barcode = txtbarcode.Text Then
66 duplicate_barcode = False
67 Else
68 'Find if barcode already exist
69 sqlSTR = "SELECT * FROM TBL_Category_Item_File WHERE Item_Barcode =" & txtbarcode.Text
70 ExecuteSQLQuery(sqlSTR)
71 If sqlDT.Rows.Count > 0 Then
72 MsgBox("Barcode Already Exist !!", MsgBoxStyle.Exclamation, "Sales and Inventory")
73 duplicate_barcode = True
74 Exit Sub
75 Else
76 duplicate_barcode = False
77 End If
78 End If
79 If Not duplicate_barcode And Not duplicate_item_number Then
80 sqlSTR = "UPDATE tbl_Category_Item_File SET Item_Name ='" & R_eplace(txtname.Text) & "', " _
81 & "Item_Description ='" & Replace(txtdesc.Text, "'", "") & "', " _
82 & "Item_Barcode =" & txtbarcode.Text & ", " _
83 & "Item_Reorder_Point =" & txtreorder.Text & ", " _
84 & "Item_Org_Price =" & CDbl(txtprice.Text) & ", " _
85 & "Unit_Measure='" & cmbUnit.Text & "', " _
86 & "Item_Price =" & CDbl(txtprice.Text) + (CDbl(txtprice.Text) * (VAT / 100)) _
87 & " WHERE Item_ID =" & Int(Split(stockID, "x")(1))
88 ExecuteSQLQuery(sqlSTR)
89 Audit_Trail(xUser_ID, TimeOfDay, "Edit Item File List")
90 End If
91
92 Else
93 'ADD
94 sqlSTR = "SELECT * FROM TBL_Category_Item_File WHERE Item_Description ='" & txtdesc.Text & "'"
95 ExecuteSQLQuery(sqlSTR)
96 If sqlDT.Rows.Count > 0 Then
97 MsgBox("Item Number Already Exist !!", MsgBoxStyle.Exclamation, "Sales and Inventory")
98 Exit Sub
99 End If
100
101 sqlSTR = "SELECT * FROM TBL_Category_Item_File WHERE Item_Barcode =" & txtbarcode.Text
102 ExecuteSQLQuery(sqlSTR)
103 If sqlDT.Rows.Count > 0 Then
104 MsgBox("Barcode Already Exists !!!", MsgBoxStyle.Critical, "Sales and Inventory")
105 Exit Sub
106 End If
107
108 sqlSTR = "INSERT INTO tbl_Category_Item_File (Catg_ID, Item_Name, Item_Description, Item_Barcode, Item_Reorder_Point, Item_Org_Price, Unit_Measure, Item_Price) VALUES(" & stockID & ", " _
109 & "'" & R_eplace(txtname.Text) & "', " _
110 & "'" & Replace(txtdesc.Text, "'", "") & "', " _
111 & txtbarcode.Text & ", " _
112 & txtreorder.Text & ", " _
113 & CDbl(txtprice.Text) & ", " _
114 & "'" & cmbUnit.Text & "', " _
115 & CDbl(txtprice.Text) + (CDbl(txtprice.Text) * (VAT / 100)) & ")"
116 ExecuteSQLQuery(sqlSTR)
117 Audit_Trail(xUser_ID, TimeOfDay, "Add New Item File List")
118 End If
119
120 MsgBox("Record Successfuly Update !", MsgBoxStyle.Information, "Sales and Inventory")
121 If UCase(globalFRM) = UCase("frmcatitemlist") Then
122 FillListView(ExecuteSQLQuery("SELECT Item_ID as 'Item ID', replace(Replace(Item_Name,'$.$',''''),'$..$',',') as 'Item Name', Item_Description as 'Description / Item Number', Item_Barcode as 'Barcode', Item_Reorder_Point as 'Reorder Point', Unit_Measure as 'Measure', Item_Price as 'Price' FROM tbl_Category_Item_File WHERE Catg_ID =" & FrmCatITEMList.lstCategory.FocusedItem.Text & " ORDER BY Item_Name"), FrmCatITEMList.lstItems, 1)
123 ElseIf UCase(globalFRM) = UCase("frmcatitemlist2") Then
124 FillListView(ExecuteSQLQuery("SELECT Item_ID as 'Item ID', replace(Replace(Item_Name,'$.$',''''),'$..$',',') as 'Item Name', Item_Description as 'Description / Item Number', Item_Barcode as 'Barcode', Item_Reorder_Point as 'Reorder Point', Unit_Measure as 'Measure', Item_Price as 'Price' FROM tbl_Category_Item_File WHERE Catg_ID =" & FrmCatList.lstCategory.FocusedItem.Text & " ORDER BY Item_Name"), FrmCatList.lstItems, 1)
125 Else
126 FillListView(ExecuteSQLQuery("SELECT Item_ID as 'ID', Catg_ID as 'Category ID', replace(Replace(Item_Name,'$.$',''''),'$..$',',') as 'Name', Item_Description as 'Description', Item_Barcode as 'Barcode', Item_Reorder_Point as 'Reorder Point', Item_Price as 'Price', Unit_Measure as 'Measure' FROM TBL_Category_Item_File ORDER BY Item_Name"), FrmCatList.lstCat, 1)
127 ' FillListView(ExecuteSQLQuery("SELECT Item_ID as 'ID', Catg_ID as 'Category ID', Item_Name as 'Name', Item_Description as 'Description', Item_Barcode as 'Barcode', Item_Reorder_Point as 'Reorder Point', Unit_Measure as 'Measure', Item_Price as 'Price' FROM TBL_Category_Item_File"), FrmCatList.lstCat, 1)
128 End If
129 Me.Close()
130 End Sub
131
132 Private Sub FrmCatITEMADD_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
133 Me.Text = "ITEM"
134 End Sub
135
136 Private Sub FrmCatITEMADD_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
137 'Dim i As Integer
138 stockID = globalID
139 FILLComboBox2("SELECT ID, Description FROM TBL_Unit_Measure", cmbUnit)
140 If Split(Me.Text, " - ")(1) = "Edit" Then
141 sqlSTR = "SELECT * FROM tbl_Category_Item_File WHERE Item_ID =" & Split(stockID, "x")(1)
142 ExecuteSQLQuery(sqlSTR)
143 If sqlDT.Rows.Count > 0 Then
144 txtID.Text = sqlDT.Rows(0)("Item_ID")
145 txtname.Text = R_Change(sqlDT.Rows(0)("Item_Name"))
146 txtdesc.Text = R_Change(sqlDT.Rows(0)("Item_Description"))
147 txtbarcode.Text = sqlDT.Rows(0)("Item_Barcode")
148 txtreorder.Text = sqlDT.Rows(0)("Item_Reorder_Point")
149 txtprice.Text = Format(sqlDT.Rows(0)("Item_Org_Price"), "###,###.00")
150 cmbUnit.Text = sqlDT.Rows(0)("Unit_Measure")
151 ' For i = 0 To cmbUnit.Items.Count - 1
152 ' If cmbUnit.Items.Count > 0 Then
153 ' If Split(cmbUnit.Items(i), " - ")(1) = sqlDT.Rows(0)("Unit_Measure") Then
154 ' cmbUnit.Text = cmbUnit.Items(i)
155 ' End If
156 ' End If
157 ' Next
158 End If
159 Else
160 txtID.Text = ""
161 txtname.Text = ""
162 txtdesc.Text = ""
163 txtbarcode.Text = ""
164 txtreorder.Text = ""
165 'cmbUnit.Text = sqlDT.Rows(0)("ID") & " - " & sqlDT.Rows(0)("Description")
166 End If
167 End Sub
168
169 Private Sub txtreorder_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtreorder.TextChanged
170 txtreorder.Text = str_Filter(txtreorder, 48, 57, 0, 0)
171 End Sub
172
173 Private Sub txtbarcode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtbarcode.TextChanged
174 txtbarcode.Text = str_Filter(txtbarcode, 48, 57, 0, 0)
175 End Sub
176
177 Private Sub txtprice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtprice.TextChanged
178 txtprice.Text = str_Filter(txtprice, 48, 57, 46, 1)
179 If txtprice.Text = "0" Or txtprice.Text = "" Then txtprice.Text = "1"
180 End Sub
181
182 Private Sub txtdesc_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtdesc.TextChanged
183 txtdesc.Text = filter_Special_Char(str_Filter(txtdesc, 48, 122, 32, 50))
184 End Sub
185
186 Private Sub txtname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtname.TextChanged
187 'txtItemName.Text = filter_Special_Char(str_Filter(txtItemName, 39, 122, 32, 40))
188 txtname.Text = filter_Special_Char(str_Filter(txtname, 34, 122, 32, 50))
189 End Sub
190 End Class